{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="ch-row ch-info-form">
            <p class="flex1">产品分类：</p>
            <div class="flex2 ch-row">
                <select class="chan form-control" name="chan">
                    <option selected="selected">请选择问题</option>
                    <option value="0">套餐</option>
                    <option value="1">维修与安装</option>
                    <option value="2">其他</option>
                </select>
            </div>
        </div>
        
        <div class="cp">

        </div>
        <div class="ch-row ch-info-form cdcd">
            <p class="flex1">单价：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <span>$</span>
                <input type="text" class="dan1" name="un_Price" readonly="readonly">
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">方量：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <input type="text" name="square" class=" fang" style="width: 55%">
                <input type="text" readonly="readonly" name="company" class="companys"
                       style="width: 15%; border-left: 1px solid #ddd; text-align: right;">
                <span style="width: 30%; border: none; padding-left: 5px;"> / 单位</span>     
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">质保：</p>
            <div class="flex2 ch-row" style="align-items: center">
                <input style="margin: 0" type="radio" value="0" name="zhi" class="zhi" checked="checked">
                <span style="margin: 0 20px 0 5px;">否</span>
                <input style="margin: 0" type="radio" value="1" name="zhi" class="zhi">
                <span style="margin: 0 20px 0 5px;">是</span>
            </div>
        </div>
        <input class="order_id" type="hidden" name='order_id' value="{$data.order_id}">
        <input class="order_id" type="hidden" name='type' value="{$type}">
        <div class="ch-row ch-info-form">
            <p class="flex1">总价：</p>
            <div class="flex2 ch-row ch-info-form-price">
                <span>$</span>
                <input type="text" class="jia"  name="to_prices" readonly="readonly" >
                <!-- <span class="input-group-addon">.00</span> -->
            </div>
        </div>
        
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交 </button>
            </div>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>
    $('.chan').bind("change", function () {
        $('.shan').remove();
        var cha = $(".chan option:selected").val();
        if (cha == 0) {
            var html =`
                <div class="ch-row ch-info-form shan">
                    <input type="hidden" name="qi_rmakes" value="">
                    <p class="flex1">套餐选择：</p>
                    <div class="flex2">
                        <select name="class_a" class="class_a2 form-control">
                            <option selected="selected" value="">请选择</option>
                            {volist name="gs" id="v"}
                            <option value="{$v.product_id}">{$v.product_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b form-control">
                            <option selected="selected">请选择问题</option>
                        </select>
                    </div>
                </div>`
            $(".cp").append(html);

            $('.cdcd').css('visibility','block');

        } else if (cha == 1) {
            $('.shan').remove();
            var html = `
                <div class="ch-row ch-info-form shan">
                    <input type="hidden" name="qi_rmakes" value="">
                    <p class="flex1">清单选择：</p>
                    <div class="flex2">
                        <select name="class_a" class="class_a1 form-control">
                            <option selected="selected" value="">请选择</option>
                            {volist name="po" id="v"}
                            <option value="{$v.detailed_id}">{$v.detailed_title}</option>\n
                            {/volist}
                        </select>
                        <select name="class_b" class="class_b1 form-control">
                            <option selected="selected">请选择</option>
                        </select>
                    </div>
                </div>`
            $(".cp").append(html);
            $('.cdcd').css('visibility','block');
        } else if (cha == 2) {
            var html = `
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标题：</p>
                    <div class="flex2">
                        <input type="text" name="class_a" placeholder="请输入标题" class=" form-control">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">单位：</p>
                    <div class="flex2">
                        <select style="width: 20%;padding: 0.4%;display: inline-block"  name="companys" class="class_a3 form-control">
                        <option selected="selected" name="company">请选择</option>
                        {volist name="g" id="v"}
                        <option value="{$v.title}">{$v.title}</option>\n
                        {/volist}
                        </select>
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">标价：</p>
                    <div class="flex2">
                        <input type="number" name="un_Prices" placeholder="请输入标价" class="un_Price form-control">
                    </div>
                </div>
                <div class="ch-row ch-info-form shan">
                    <p class="flex1">备注：</p>
                    <div class="flex2">
                        <textarea name="qi_rmakes" class="form-control"></textarea>
                    </div>
                </div>`
            $(".cp").append(html);
            $('.cdcd').css('visibility','hidden');
            $('.o').remove();
            $('#price_rule').html('');
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');
        }

    });
    $(document).on("change", ".class_a1", function () {
        var detaileds_id = $(this).val();
        console.log(detaileds_id);
        $.post("{:url('index/order/detailed')}", {detaileds_id: detaileds_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var pris;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "' >" + data[i]['detailed_title'] + "</option>";
                    artificial = data[0]['artificial'];
                    dan = data[0]['titles'];
                    pris = data[0]['rmakes'];
                }
            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.class_b1').html(html);
            $('.dan1').val(artificial);
            $('.companys').val(dan);
            $('#price_rule').html(pris);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });
    });
    $(document).on("change", ".class_a2", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var price_rule;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['product_id'] + "' >" + data[i]['product_title'] + "</option>";
                    artificial = data[0]['prices'];
                    price_rule = data[0]['price_rules'];
                    dan = data[0]['titles'];
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }
            $('.companys').val(dan);
            $('.class_b').html(html);
            $('.dan1').val(artificial);
            $('#price_rule').html(price_rule);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan_dan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var price_rule;
            artificial = data['prices'];
            dan = data['titles'];
            price_rule = data['price_rules'];
            $('.companys').val(dan);
            $('#price_rule').html(price_rule);

            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b1", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/detailed_dan')}", {detaileds_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var pris;
            artificial = data['artificial'];
            dan = data['titles'];
            pris = data['rmakes'];
            $('#price_rule').html(pris);
            $('.companys').val(dan);
            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".un_Price", function () {
        $('.fang').val('');
        $('.jias').val('');
        $('.jia').val('');

    });
    $('.fang').bind("change", function () {

        //向input输入框中赋值
        var chan = $('.chan').val();
        var companys = $('.dan1').val();
        var fang = $('.fang').val();
        if (chan == 2) {
            var un_Price = $('.un_Price').val();

            var num =((un_Price * 1000) * fang) / 1000;
            num = num.toFixed(2);
            $('.jia').val(num);
            $('.jias').val(num);
        } else {


            var num =((companys * 1000) * fang) / 1000;
            num = num.toFixed(2);
            $('.jia').val(num);
            $('.jias').val(num);
        }


    });


    /***
     *
     *
     * 提交代码
     * */
    $('.radius').click(function () {
        var src = "{:Url('index/order/zeng')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        setTimeout("window.parent.location.reload()", 1);

                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    /**
     * 赠送项目
     *
     **/
    $(".give_a").bind("change", function () {
        give_b();
    });

    function give_b() //市
    {
        var parent_ids = $(".give_a").find("option:selected").val(); //省id
        console.log(parent_ids);
        $.post("{:url('index/order/detailed')}", {detaileds_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "'>" + data[i]['detailed_title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.give_b').html(html);
        });
    }







</script>
</body>
</html>